package cn.ulc.socket.weapp.controller;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import cn.ulc.common.model.param.PaginationParam;
import cn.ulc.common.util.Result;
import cn.ulc.socket.weapp.model.dto.*;
import cn.ulc.socket.weapp.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Min;

@Validated
@RestController
@RequestMapping(value = "/wechat/goods")
public class GoodsController {
    private static final Log log = LogFactory.get();
    @Autowired
    GoodsService goodsService;


    @GetMapping("/typeList/{id}")
    public Result findTypeList(@PathVariable("id") Long id) {
        GoodsTypeListDTO dto = goodsService.findTypeList(id);
        return Result.success(dto);
    }
    @GetMapping("/findNewGoodsList/{id}")
    public Result findNewGoodsList(@PathVariable("id") Long id) {
        GoodsListDTO dto = goodsService.findNewGoodsList(id);
        return Result.success(dto);
    }
    @GetMapping("/findTypeListByParentId/{id}")
    public Result findTypeListByParentId(@PathVariable Long  id) {
        GoodsTypeListDTO dto = goodsService.findTypeListByParentId(id);
        return Result.success(dto);
    }

    @GetMapping("/list")
    public Result findList(@Validated @Min(1) Long typeId, String searchKey,PaginationParam param) {
        GoodsListDTO dto = goodsService.findList(typeId,searchKey, param);
        return Result.success(dto);
    }

    @GetMapping("/sku")
    public Result findSkuList(@Validated @Min(1) Long goodsId) {
        GoodsSkuDTO dto = goodsService.findSku(goodsId);
        return Result.success(dto);
    }
    @GetMapping("/detail/{barCode}")
    public Result findDetail(@PathVariable String barCode) {
        GoodsDTO dto = goodsService.findDetail(barCode);
        return Result.success(dto);
    }



}
